<?php
namespace ApigilityGroup\V1\Rest\ParticipationDetail;

use ApigilityCatworkFoundation\Base\ApigilityEntity;
use ApigilityUser\DoctrineEntity\User;
use ApigilityUser\V1\Rest\User\UserEntity;
use Zend\ServiceManager\ServiceManager;
use ApigilityOrder\DoctrineEntity\Order;
use ApigilityOrder\V1\Rest\Order\OrderEntity;
use ApigilityVIP\DoctrineEntity\Contract;
use ApigilityVIP\V1\Rest\Contract\ContractEntity;
use ApigilityGroup\DoctrineEntity\Group;
use ApigilityGroup\V1\Rest\Group\GroupEntity;

class ParticipationDetailEntity extends ApigilityEntity
{
    /**
     * @Id @Column(type="integer")
     * @GeneratedValue
     */
    protected $id;

    /**
     * 参团价格
     *
     * @Column(type="decimal", precision=7, scale=2, nullable=false)
     */
    protected $price;

    /**
     * 参团时间
     *
     * @Column(type="datetime",nullable=false)
     */
    protected $participation_time;

    /**
     * 过期时间
     *
     * @Column(type="datetime",nullable=false)
     */
    protected $expires;

    /**
     * 参团类型
     *
     * @Column(type="smallint", nullable=false)
     */
    protected $type;

    /**
     * 参团人员
     *
     * @ManyToOne(targetEntity="ApigilityUser\DoctrineEntity\User")
     * @JoinColumn(name="user_id", referencedColumnName="id")
     */
    protected $user;

    /**
     * 所在团
     *
     * @ManyToOne(targetEntity="Group")
     * @JoinColumn(name="group_id", referencedColumnName="id")
     */
    protected $group;

    /**
     * 合约,参团时生成的合约
     *
     * @ManyToOne(targetEntity="ApigilityVIP\DoctrineEntity\Contract")
     * @JoinColumn(name="contract_id", referencedColumnName="id")
     */
    protected $contract;

    /**
     * 订单，订单参团时生成的订单
     *
     * @ManyToOne(targetEntity="ApigilityOrder\DoctrineEntity\Order")
     * @JoinColumn(name="order_id", referencedColumnName="id")
     */
    protected $order;

    protected $services;

    /**
     * 参团状态
     *
     * @Column(type="smallint", nullable=true)
     */
    protected $status;

    public function __construct($doctrine_entity, ServiceManager $services)
    {
        parent::__construct($doctrine_entity);
        $this->services = $services;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getPrice()
    {
        return $this->price;
    }

    /**
     * @param mixed $price
     */
    public function setPrice($price)
    {
        $this->price = $price;
    }

    /**
     * @return mixed
     */
    public function getParticipationTime()
    {
        return $this->participation_time->getTimestamp();
    }

    /**
     * @param mixed $participation_time
     */
    public function setParticipationTime($participation_time)
    {
        $this->participation_time = $participation_time;
    }

    /**
     * @return mixed
     */
    public function getExpires()
    {
        return $this->expires->getTimestamp();
    }

    /**
     * @param mixed $expires
     */
    public function setExpires($expires)
    {
        $this->expires = $expires;
    }

    /**
     * @return mixed
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @param mixed $type
     */
    public function setType($type)
    {
        $this->type = $type;
    }

    /**
     * @return mixed
     */
    public function getUser()
    {
        if ($this->user instanceof User) {
            return $this->hydrator->extract(new UserEntity($this->user, $this->services));
        } else {
            return $this->user;
        }
    }

    /**
     * @param mixed $user
     */
    public function setUser($user)
    {
        $this->user = $user;
    }

    /**
     * @return mixed
     */
    public function getGroup()
    {
        if ($this->group instanceof Group) {
            return $this->hydrator->extract(new GroupEntity($this->group, $this->services));
        } else {
            return $this->group;
        }
    }

    /**
     * @param mixed $group
     */
    public function setGroup($group)
    {
        $this->group = $group;
    }

    /**
     * @return mixed
     */
    public function getContract()
    {
        if ($this->contract instanceof Contract) {
            return $this->hydrator->extract(new ContractEntity($this->contract, $this->services));
        } else {
            return $this->contract;
        }
    }

    /**
     * @param mixed $contract
     */
    public function setContract($contract)
    {
        $this->contract = $contract;
    }

    /**
     * @return mixed
     */
    public function getOrder()
    {
        if ($this->order instanceof Order) {
            return $this->hydrator->extract(new OrderEntity($this->order, $this->services));
        } else {
            return $this->order;
        }
    }

    /**
     * @param mixed $order
     */
    public function setOrder($order)
    {
        $this->order = $order;
    }

    /**
     * @return mixed
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @param mixed $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

}
